package com.akk.module.yb.model;

import com.akk.PayConstants;
import com.akk.module.yb.utils.Digest;
import org.apache.commons.httpclient.methods.multipart.Part;
import org.apache.commons.httpclient.methods.multipart.StringPart;

import java.util.ArrayList;
import java.util.List;

public class ReceiveQueryRequest {
    private String mainCustomerNumber; //代理商商户编号
    private String customerNumber; //商户编号
    private String requestId; //收款订单号
    private String createTimeBegin;
    private String createTimeEnd; //请求时间：结束时间
    private String payTimeBegin; //支付时间：开始时间
    private String payTimeEnd; //支付时间：结束时间
    private String lastUpdateTimeBegin; //更新时间：开始时间
    private String lastUpdateTimeEnd; //更新时间：结束时间
    private String status; //订单状态;
    private String busiType; //订单类型
    private String pageNo; //分页参数：页码
    private String hmac; //签名信息

    public String getMainCustomerNumber() {
        return mainCustomerNumber;
    }

    public void setMainCustomerNumber(String mainCustomerNumber) {
        this.mainCustomerNumber = mainCustomerNumber;
    }

    public String getCustomerNumber() {
        return customerNumber;
    }

    public void setCustomerNumber(String customerNumber) {
        this.customerNumber = customerNumber;
    }

    public String getRequestId() {
        return requestId;
    }

    public void setRequestId(String requestId) {
        this.requestId = requestId;
    }

    public String getCreateTimeEnd() {
        return createTimeEnd;
    }

    public void setCreateTimeEnd(String createTimeEnd) {
        this.createTimeEnd = createTimeEnd;
    }

    public String getPayTimeBegin() {
        return payTimeBegin;
    }

    public void setPayTimeBegin(String payTimeBegin) {
        this.payTimeBegin = payTimeBegin;
    }

    public String getPayTimeEnd() {
        return payTimeEnd;
    }

    public void setPayTimeEnd(String payTimeEnd) {
        this.payTimeEnd = payTimeEnd;
    }

    public String getLastUpdateTimeBegin() {
        return lastUpdateTimeBegin;
    }

    public void setLastUpdateTimeBegin(String lastUpdateTimeBegin) {
        this.lastUpdateTimeBegin = lastUpdateTimeBegin;
    }

    public String getLastUpdateTimeEnd() {
        return lastUpdateTimeEnd;
    }

    public void setLastUpdateTimeEnd(String lastUpdateTimeEnd) {
        this.lastUpdateTimeEnd = lastUpdateTimeEnd;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getBusiType() {
        return busiType;
    }

    public void setBusiType(String busiType) {
        this.busiType = busiType;
    }

    public String getPageNo() {
        return pageNo;
    }

    public void setPageNo(String pageNo) {
        this.pageNo = pageNo;
    }

    public String getHmac() {
        return hmac;
    }

    public void setHmac(String hmac) {
        this.hmac = hmac;
    }


    public static String signature(ReceiveQueryRequest request) {
        StringBuffer sb = new StringBuffer();
        sb.append(request.getMainCustomerNumber() == null ? "" : request.getMainCustomerNumber());
        sb.append(request.getCustomerNumber() == null? "":request.getCustomerNumber());
        sb.append(request.getRequestId() == null?"":request.getRequestId());
        sb.append(request.getCreateTimeBegin() == null?"":request.getCreateTimeBegin());
        sb.append(request.getCreateTimeEnd() == null?"":request.getCreateTimeEnd());
        sb.append(request.getPayTimeBegin() == null?"":request.getPayTimeBegin());
        sb.append(request.getPayTimeEnd() == null?"":request.getPayTimeEnd());
        sb.append(request.getLastUpdateTimeBegin() == null?"":request.getLastUpdateTimeBegin());
        sb.append(request.getLastUpdateTimeEnd() == null?"":request.getLastUpdateTimeEnd());
        sb.append(request.getStatus() == null?"":request.getStatus());
        sb.append(request.getBusiType() == null?"":request.getBusiType());
        sb.append(request.getPageNo() == null?"":request.getPageNo());
        System.out.println(sb.toString());
        return Digest.hmacSign(sb.toString(), PayConstants.YB_PARAMS_HMAC_KEY);
    }

    public static Part[] builderPart(ReceiveQueryRequest request) {
        List<Part> parts = new ArrayList<Part>();
        parts.add(new StringPart("mainCustomerNumber",request.getMainCustomerNumber()==null?"":request.getMainCustomerNumber(),"UTF-8"));
        parts.add(new StringPart("customerNumber",request.getCustomerNumber()==null?"":request.getCustomerNumber(),"UTF-8"));
        parts.add(new StringPart("requestId",request.getRequestId()==null?"":request.getRequestId(),"UTF-8"));
        parts.add(new StringPart("createTimeBegin",request.getCreateTimeBegin()==null?"":request.getCreateTimeBegin(),"UTF-8"));
        parts.add(new StringPart("createTimeEnd",request.getCreateTimeEnd()==null?"":request.getCreateTimeEnd(),"UTF-8"));
        parts.add(new StringPart("payTimeBegin",request.getPayTimeBegin()==null?"":request.getPayTimeBegin(),"UTF-8"));
        parts.add(new StringPart("payTimeEnd",request.getPayTimeEnd()==null?"":request.getPayTimeEnd(),"UTF-8"));
        parts.add(new StringPart("lastUpdateTimeBegin",request.getLastUpdateTimeBegin()==null?"":request.getLastUpdateTimeBegin(),"UTF-8"));
        parts.add(new StringPart("lastUpdateTimeEnd",request.getLastUpdateTimeEnd()==null?"":request.getLastUpdateTimeEnd(),"UTF-8"));
        parts.add(new StringPart("status",request.getStatus()==null?"":request.getStatus(),"UTF-8"));
        parts.add(new StringPart("busiType",request.getBusiType()==null?"":request.getBusiType(),"UTF-8"));
        parts.add(new StringPart("pageNo",request.getPageNo()==null?"":request.getPageNo(),"UTF-8"));
        parts.add(new StringPart("hmac",request.getHmac() == null ?"":request.getHmac(),"UTF-8"));
        return parts.toArray(new Part[parts.size()]);
    }

    public String getCreateTimeBegin() {
        return createTimeBegin;
    }

    public void setCreateTimeBegin(String createTimeBegin) {
        this.createTimeBegin = createTimeBegin;
    }
}
